package algorithm.poj.p3000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.StringTokenizer;


/**
 * 分析：
 * 实现：
 * 经验：
 * 教训：
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P3176 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P3176.class.getResource("P3176.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		
		String line = stdin.readLine();
		int N = Integer.valueOf(line.trim());
		
		int[] ts = new int[3];
		StringTokenizer st = new StringTokenizer(stdin.readLine());
		ts[0] = 0;
		ts[1] = Integer.valueOf(st.nextToken());
		ts[2] = 0;
		
		for (int i = 1; i < N; i ++) {
			st = new StringTokenizer(stdin.readLine());
			int[] ds = new int[i+3];
			ds[0] = ds[i+2] = 0;
			for (int j = 1; j < i+2; j ++) {
				ds[j] = Math.max(ts[j-1], ts[j]) + Integer.valueOf(st.nextToken());
			}
			ts = ds;
		}
		
		int max = -1;
		for (int i = 1; i < ts.length - 1; i ++) {
			if (ts[i] > max) {
				max = ts[i];
			}
		}
		System.out.println(max);
	}
}